Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs-progs: refactor around btrfs_insert_file_extent() #919

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

adam900710
Copy link
Collaborator

Although btrfs_insert_file_extent() is a btrfs-progs specific function,
it's pretty close (although not yet similiar enough to cross-port) to
insert_reserved_file_extent() from kernel.

That kernel function uses an on-stack btrfs_file_extent_item to pass all
the needed parameters, supporting both compressed and uncompressed data
extents.

That is way more flex than btrfs_insert_file_extent() from btrfs-progs,
which can not support:

  • Non-zero offset
  • Ram_bytes larger than num_bytes
  • Compressed extents

To prepare for the incoming support of compressed data extents
generation for mkfs --rootdir, we need a more generic way to insert file
extents.

This patch improve the situation by:

  • Move btrfs_record_file_extent() to be a convert specific function
    The extra handling are all for converted btrfs, and can split extents
    where regular btrfs doesn't want.

    For mkfs/rootdir.c, the only caller out of convert, introduce a
    helper, insert_reserved_file_extent() to handle the case.

  • Make btrfs_insert_file_extent() to accept an on-stack btrfs_file_extent_item
    Just like insert_reserved_file_extent() from kernel.

    Allowing us to customize ever member of the btrfs_file_extent_item.
    Now this makes btrfs_insert_file_extent() flex enough for converted
    fs, and the incoming compressed file extents.

The function btrfs_record_file_extent() has extra handling that's
specific to convert, like allowing the range to be split by block group
boundary and image file extent boundary.

All of these split can only lead to corruption for non-converted fs.
As the only caller out of btrfs-convert is rootdir, which expects the
file extent item insert to respect the reserved data extent, and never
to be split.

Thankfully this is not going to cause huge problem, as
btrfs_record_file_extent() has extra checks if the data extent overlaps
with any existing one, and if it doesn't the handling will be the same
as the kernel.

But to avoid abuse, change btrfs_record_file_extent() by:

- Rename it to btrfs_convert_file_extent()
  And add extra comments on that it is specific to btrfs-convert.

- Move it to convert/common.[ch]

- Introduce a helper insert_reserved_file_extent() for rootdir.c

Signed-off-by: Qu Wenruo <[email protected]>
…le extent item

Just like insert_reserved_file_extent() from the kernel, we can make
btrfs_insert_file_extent() to accept an on-stack file extent item
directly.

This makes btrfs_insert_file_extent() more flex, and it can now handle
the converted file extent where it has an non-zero offset.

And this makes it much easier to expand for future compressed file
extent generation.

Signed-off-by: Qu Wenruo <[email protected]>
@maharmstone
Copy link
Contributor

These changes look sensible to me. They certainly make my compression code a lot simpler.

There's a couple of existing issues still with insert_reserved_file_extent (it confuses num_bytes and disk_num_bytes, and sets ins_key but doesn't use it), but I'll fix them with my patches.

English nitpick too in the patch title: no "to" in "btrfs-progs: make btrfs_insert_file_extent() to accept an on-stack file extent item". I know this makes no sense: it's "order/force/tell/advise X to Y", but "make X Y".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants